package com.dhh.nutrition.activity;

import java.util.ArrayList;
import java.util.List;
import com.dhh.nutrition.R;
import greendroid.app.GDActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.view.View;

public class HomeActivity extends GDActivity implements View.OnClickListener {	
	private EditText foodName;
	private Spinner foodGroup;
	private Button bSearch;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setActionBarContentView(R.layout.home);
        
        initView();
        initActionBar();
    }
	
	public void initActionBar(){
        getActionBar().removeViewAt(0);
		getActionBar().setTitle("Nutrition Factc Assistant");
        getActionBar().setBackgroundColor(Color.rgb(154, 205, 50));
        getActionBar().getChildAt(0).
        	setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View v) {
					
				}});
	}
	
	private void initView(){
		foodName = (EditText)findViewById(R.id.home_food_name);
		foodGroup = (Spinner)findViewById(R.id.home_food_group);
		bSearch = (Button)findViewById(R.id.home_search_button);
		bSearch.setOnClickListener(this);
		
		List<String> list = new ArrayList<String>();
		list.add("All Foods");
		list.add("Dairy and Egg Products");
		list.add("Spices and Herbs");
		list.add("Baby Foods");
		list.add("Fats and Oils");
		list.add("Poultry Products");
		list.add("Soups, Sauces, and Gravies");
		list.add("Sausages and Luncheon Meats");
		list.add("Breakfast Cereals");
		list.add("Fruits and Fruit Juices");
		list.add("Pork Products");
		list.add("Vegetables and Vegetable Products");
		list.add("Nut and Seed Products");
		list.add("Beef Products");
		list.add("Beverages");
		list.add("Finfish and Shellfish Products");
		list.add("Legumes and Legume Products");
		list.add("Lamb, Veal, and Game Products");
		list.add("Baked Products");
		list.add("Sweets");
		list.add("Cereal Grains and Pasta");
		list.add("Fast Foods");
		list.add("Meals, Entrees, and Sidedishes");
		list.add("Snacks");
		list.add("Ethnic Foods");
		list.add("Restaurant Foods");
		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, list);
		dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		foodGroup.setAdapter(dataAdapter);
	}

	@Override
	public void onClick(View v) {
		if(v.getId()==R.id.home_search_button){
			Intent intent = new Intent(HomeActivity.this, SearchFoodActivity.class);	
			intent.putExtra("sFoodName", foodName.getText().toString());
			String fg = foodGroup.getSelectedItem().toString();
			if(fg.equals("All Foods")) fg = null;
			intent.putExtra("sFoodGroup", fg);
			startActivity(intent);
		}
	}
}
